/*
 * Copyright 2018-10-17 7:49:26 The JA-SIG Collaborative. All rights reserved.
 * distributed with thi file and available online at
 */
package com.lap.scp.erp.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.lap.scd.commons.page.Page;
import com.lap.scd.commons.page.PageResult;
import com.lap.scd.commons.result.Resp;
import com.lap.scp.admin.utils.DictionaryUtils;
import com.lap.scp.erp.ao.ReceivablesDetailAO;
import com.lap.scp.erp.domain.ReceivablesDetailDO;
import com.lap.scp.erp.query.ReceivablesDetailQueryVO;

/**
 * <pre>
 *  收款明细控制对象，提供 收款明细 新增,编辑,查询等操作。
 *  控制层统一命名规则：
 *  进入新增 	add,
 *  增加保存 	save,
 *  进入修改 	edit,
 *  修改保存 	update,
 *  查询分页 	queryPage,
 *  根据ID查询 	get,
 *  删除 		deleteById
 *
 * </pre>
 * 
 * @author 劳水生 Exp
 * @Date 2018-10-17 7:49:26
 * @since 2.0.0
 */
@Controller
@RequestMapping("receivablesDetail")
public class ReceivablesDetailController {
	/**
	 * 收款明细应用流程对象
	 */
	@Resource
	private ReceivablesDetailAO receivablesDetailAO;

	/**
	 * <pre>
	 * 新增保存收款明细
	 * </pre>
	 * 
	 * @param detailDO
	 * @param error
	 * @return
	 */
	@PostMapping(value = "add")
	@ResponseBody
	public Resp<ReceivablesDetailDO> add(ReceivablesDetailDO detailDO) {
		return receivablesDetailAO.insertReceivablesDetail(detailDO);
	}

	/**
	 * <pre>
	 * 根据收款ID查询收款明细信息
	 * </pre>
	 * 
	 * @param receivablesId
	 * @return
	 */
	@GetMapping(value = "getByReceivablesId/{receivablesId}")
	public ModelAndView getByReceivablesId(@PathVariable Integer receivablesId) {
		ModelAndView andView = new ModelAndView();
		Resp<List<ReceivablesDetailDO>> resp = receivablesDetailAO.queryByReceivablesId(receivablesId);
		if (resp.isSuccess()) {
			andView.setViewName("erp/receivablesDetail");
			andView.addObject("list", resp.getData());
			andView.addObject("payMap", DictionaryUtils.PAY_MAP);
		} else {
			andView.setViewName("error");
		}
		return andView;
	}

	/**
	 * <pre>
	 * 根据条件、分页信息查询收款明细
	 * // TODO 生成的代码，如果确认你已经使用该方法，请删除该行注释，不然后续清理代码的时候，将会删除该方法
	 * </pre>
	 * 
	 * @param page
	 * @param queryVO
	 * @return
	 */
	@RequestMapping(value = "list", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView queryPage(Page page, ReceivablesDetailQueryVO queryVO) {
		ModelAndView andView = new ModelAndView();

		PageResult<ReceivablesDetailDO> pr = receivablesDetailAO.queryPage(page, queryVO);
		if (pr.isSuccess()) {
			andView.setViewName("receivablesDetailList");
			andView.addObject("queryVO", queryVO);
			andView.addObject("pr", pr);
		} else {
			andView.setViewName("error");
		}
		return andView;
	}

}
